#include "HeaderHttpRequest.h"
#include "EasyHttpLog.h"

FHeaderHttpRequest::FHeaderHttpRequest()
{

}

bool FHeaderHttpRequest::NeedDeserialized() const
{
	return m_eStage == EHttpRequestStage::eStage_Succeed;
}

void FHeaderHttpRequest::Serialized(FMemoryWriter &Write)
{
	Write << m_nContentLen;
	Write << m_LastModify;
}

void FHeaderHttpRequest::Deserialized(FBufferReader &Reader)
{
	Reader << m_nContentLen;
	Reader << m_LastModify;
	m_eStage = EHttpRequestStage::eStage_Succeed;
}

void FHeaderHttpRequest::InitHeader()
{
	FBaseHttpRequest::InitHeader();
	m_pRequest->SetURL(m_Url);
	m_pRequest->SetVerb(TEXT("HEAD"));
}

void FHeaderHttpRequest::CompleteCallback(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bConnectedSuccessfully)
{
	if (IsResponseSucceed(Request, Response, bConnectedSuccessfully))
	{
		m_nContentLen = Response->GetContentLength();
		m_LastModify = Response->GetHeader("Last-Modified");
	}
	FBaseHttpRequest::CompleteCallback(Request, Response, bConnectedSuccessfully);
}

void FHeaderHttpRequest::HeaderReceivedCallback(FHttpRequestPtr Request, const FString& HeaderName, const FString& NewHeaderValue)
{
	FBaseHttpRequest::HeaderReceivedCallback(Request, HeaderName, NewHeaderValue);
}

void FHeaderHttpRequest::ProgressCallback(FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived)
{
	FBaseHttpRequest::ProgressCallback(Request, BytesSent, BytesReceived);
}

void FHeaderHttpRequest::WillRetryCallback(FHttpRequestPtr Request, FHttpResponsePtr Response, float SecondsToRetry)
{
	FBaseHttpRequest::WillRetryCallback(Request, Response, SecondsToRetry);
}
